const mongoose = require('mongoose')
/**
 * 会话
 */
module.exports = mongoose.model(
	'Conversation',
	new mongoose.Schema({
		// 会话名称，默认为会话包含用户呢称的组合
		title: String,
		// 会话图标
		avatar: String,
		// 会话包含的用户ID
		crowd: [
			{
				type: mongoose.Schema.Types.ObjectId,
				ref: 'User'
			}
		],
		lastTime: {
			type: Date,
			default: Date.now(),
			get (val) {
				return new Date(val).toLocaleString()
			}
		},
		created: {
			type: Date,
			default: Date.now(),
			get (val) {
				return new Date(val).toLocaleString()
			}
		},
		updated: {
			type: Date,
			default: Date.now(),
			get (val) {
				return new Date(val).toLocaleString()
			}
		}
	}, { toJSON: { getters: true } })
)